#include "stdafx.h"
#include "platform.h"

#define SEM_MAXVALUE 100000


#if (PLATFORM_TYPE == PLATFORM_WIN32)
p_semaphore::p_semaphore()
{
	hSemaphore = CreateSemaphore(NULL, 0, SEM_MAXVALUE, NULL);
	if (hSemaphore == NULL)
	{
		fprintf_s(stderr, "error in creating semaphore object\n");
	}
}
p_semaphore::~p_semaphore()
{
	CloseHandle(hSemaphore);
}
void p_semaphore::consume()
{
	WaitForSingleObject(hSemaphore, INFINITE);
}

void p_semaphore::produce()
{
	ReleaseSemaphore(hSemaphore, 1, NULL);
}


p_mutex::p_mutex()
{
	hMutex = CreateMutex(NULL, FALSE, NULL);
	if (hMutex == NULL)
	{
		fprintf_s(stderr, "error in creating mutex object\n");
	}
}
p_mutex::~p_mutex()
{
	CloseHandle(hMutex);
}
void p_mutex::lock()
{
	WaitForSingleObject(hMutex, INFINITE);
}

void p_mutex::unlock()
{
	ReleaseMutex(hMutex);
}
#endif

#if (PLATFORM_TYPE == PLATFORM_LINUX)
#endif
